package com.neuedu.yyzx.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neuedu.yyzx.common.Ret;
import com.neuedu.yyzx.po.Nurselevel;
import com.neuedu.yyzx.service.NursecontentService;
import com.neuedu.yyzx.service.NurselevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nurselevel")
public class NurseLevelController {
    @Autowired
    private NurselevelService nurselevelService;

    @GetMapping("/list")
    public Ret list() {
        return Ret.ok(nurselevelService.list());
    }

    @GetMapping("/page")
    public Ret<List<Nurselevel>> page(Page<Nurselevel> page, Nurselevel nurselevel) {
        LambdaQueryWrapper<Nurselevel> queryWrapper = new LambdaQueryWrapper<>();
        if (nurselevel.getLevelName() != null && !"".equals(nurselevel.getLevelName())) {
            queryWrapper.like(Nurselevel::getLevelName, nurselevel.getLevelName());
        }
        queryWrapper.orderByDesc(Nurselevel::getId);
        page = nurselevelService.page(page, queryWrapper);
        return Ret.ok(page);
    }

    @PostMapping("/saveOrUpdate")
    public Ret<Boolean> saveOrUpdate(@RequestBody Nurselevel nurselevel) {
        return Ret.ok(nurselevelService.saveOrUpdate(nurselevel));
    }

    @GetMapping("/getById/{id}")
    public Ret<Nurselevel> getById(@PathVariable int id) {
        Nurselevel result = nurselevelService.getById(id);
        return Ret.ok(result);
    }
    @GetMapping("/getByName/{name}")
    public Ret<Page<Nurselevel>> getByName(@PathVariable String name,Page<Nurselevel> page ) {
        LambdaQueryWrapper<Nurselevel> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(Nurselevel::getLevelName, name);
        queryWrapper.orderByDesc(Nurselevel::getId);
        Page<Nurselevel> resultPage = nurselevelService.page(page, queryWrapper);
        return Ret.ok(resultPage);
    }

    @DeleteMapping("/{id}")
    public Ret<Boolean> removeById(@PathVariable int id) {
        return Ret.ok(nurselevelService.removeById(id));
    }
}
